<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<shiro:hasPermission name="MG_PERMISSION" />
	<div class="easyui-panel" style="width: fill; padding: 5px;" data-options="iconCls:'icon-search',border:false">
		<div class="easyui-panel" title="快捷查询" style="width: fill; margin-bottom: 5px;"
			data-options="iconCls:'icon-search',border:true">
			<table>
				<tr>
					<td>客户编码：<input type="text" id="txtCode" name="params.code" value="${params.code}" /></td>
					<td>客户名称：<input type="text" id="txtName" name="params.name" value="${params.name}" /></td>
					<td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="query()">查询</a></td>
					<td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="openCustomerQuery()">高级查询</a></td>
				</tr>
			</table>
		</div>
		<table id="gridCustomers" class="easyui-datagrid" title="客户列表" style="width: fill; height: 600px;"
			data-options="singleSelect:true,iconCls:'icon-database',border:true,nowrap:true,rownumbers:true,pagination:true,pageSize:50,pageList:[20,50,100],url:'${patch}/business/customer/list.do'">
			<thead>
				<tr>
					<th data-options="field:'id',hidden:true">Id</th>
					<th data-options="field:'code',align:'center'">客户编码</th>
					<th data-options="field:'name',align:'center'">客户名称</th>
					<th data-options="field:'sex',align:'center',formatter:sexformat">性别</th>
					<th data-options="field:'age',align:'center'">年龄</th>
					<th data-options="field:'cardCategoryName',align:'center'">证件类型</th>
					<th data-options="field:'cardNumber',align:'center'">证件号码</th>
					<th data-options="field:'birthdayString',align:'center'">出生日期</th>
					<th data-options="field:'phone1',align:'center'">电话1</th>
					<th data-options="field:'phone2',align:'center'">电话2</th>
					<th data-options="field:'createDateString',align:'center'">注册日期</th>
					<th data-options="field:'typeName',align:'center'">客户类型</th>
					<th data-options="field:'levelName',align:'center'">客户级别</th>
					<th data-options="field:'incomeName',align:'center'">月收入</th>
					<th data-options="field:'professionName',align:'center'">职业</th>
					<th data-options="field:'reveiveDoc',align:'center',formatter:booleanFormat">是否接受会刊</th>
					<th data-options="field:'createUserName',align:'center'">创建人</th>
				</tr>
			</thead>
		</table>
		<div id="winCustomer" class="easyui-window" title="添加新功能"
			data-options="modal:true,closed:true,minimizable:false,maximizable:false,collapsible:false,iconCls:'icon-save'"
			style="width: 580px; height: 520px; padding: 5px;"></div>

		<div id="winCustomerQuery" class="easyui-window" title="高级查询"
			data-options="modal:true,closed:true,minimizable:false,maximizable:false,collapsible:false,iconCls:'icon-save'"
			style="width: 340; height: 420px; padding: 5px;">
			<s:set id="receiveOptions" value="#{'true':'是','false':'否'}" />
			<table align="center">
				<tr>
					<td width="300" align="left">是否接受会刊： <s:select list="receiveOptions" name="receiveDoc" id="receiveDoc" theme="simple"
							emptyOption="true" />
					</td>
				</tr>
				<tr>
					<td>电话号码：<input type="text" id="txtPhone" name="txtPhone" />
					</td>
				</tr>
				<tr>
					<td>客户类型：<s:select list="types" listKey="id" listValue="name" name="typeId" id="typeId" theme="simple"
							emptyOption="true" />
					</td>
				</tr>
				<tr>
					<td>客户级别：<s:select list="levels" listKey="id" listValue="name" name="levelId" id="levelId" theme="simple"
							emptyOption="true" /></td>
				</tr>
				<tr>
					<td>月收入：<s:select list="incomes" listKey="id" listValue="name" name="incomeId" id="incomeId" theme="simple"
							emptyOption="true" /></td>
				</tr>
				<tr>
					<td>职业：<s:select list="professions" listKey="id" listValue="name" name="professionId" id="professionId" theme="simple"
							emptyOption="true" /></td>
				</tr>
				<tr>
					<td>个人爱好： <s:select list="hobbies" listKey="id" listValue="name" name="hobbiesId" id="hobbiesId" theme="simple"
							emptyOption="true" />
					</td>
				</tr>
			</table>

			<div style="text-align: center; padding: 5px">
				<a href="javascript:void(0)" class="easyui-linkbutton" onclick="advQueryCustomer()">确定</a> <a href="javascript:void(0)"
					class="easyui-linkbutton" onclick="closeCustomerQuery()">关闭</a>
			</div>
		</div>

	</div>

	<script type="text/javascript">
		$('#gridCustomers').datagrid({
			toolbar : [ {
				text : '添加',
				iconCls : 'icon-add',
				handler : function() {
					$('#winCustomer').window({
						href : '${path}/business/customer/addNew.do'
					});
					$('#winCustomer').window('open');
				}
			}, {
				text : '编辑',
				iconCls : 'icon-edit',
				handler : function() {
					var data = $("#gridCustomers").datagrid('getSelected');
					if (null == data) {
						$.messager.alert('提示信息', '请选择要编辑的行。');
					} else {
						$('#winCustomer').window({
							href : '${path}/business/customer/edit.do?id=' + data.id
						});
						$('#winCustomer').window('open');
					}
				}
			}, {
				text : '删除',
				iconCls : 'icon-remove',
				handler : function() {
					var data = $("#gridCustomers").datagrid('getSelected');
					if (null == data) {
						$.messager.alert('提示信息', '请选择要删除的行。');
					} else {
						$.messager.confirm('确认操作', '你确定要删除所选客户信息吗！？', function(isOk) {
							if (isOk) {
								$.ajax({
									url : '${path}/business/customer/remove.do?id=' + data.id,
									type : 'GET',
									dataType : 'json',
									success : function(data) {
										if (null != data.message) {
											$.messager.alert('提示信息', data.message);
										} else {
											$.messager.alert('提示信息', '删除成功！');
										}
										refreshgridCustomers();
									}
								});
							}
						});
					}
				}
			}, {
				text : '导出',
				iconCls : 'icon-excel',
				handler : function() {
					exportToExcel("gridCustomers", "客户列表");
				}
			} ]
		});

		$('#winCustomer').window({
			onClose : function() {
				refreshgridCustomers();
			}
		});

		function refreshgridCustomers() {
			$('#gridCustomers').datagrid('reload');
		}

		function closewinCustomer() {
			$('#winCustomer').window('close');
		}

		function openCustomerQuery() {
			$("#winCustomerQuery").window("open");
		}

		function closeCustomerQuery() {
			$("#winCustomerQuery").window("close");
		}

		function query() {
			$("#gridCustomers").datagrid('load', {
				"params.code" : $("#txtCode").val(),
				"params.name" : $("#txtName").val()
			});
		}

		function advQueryCustomer() {
			closeCustomerQuery();
			$("#gridCustomers").datagrid('load', {
				"params.code" : $("#txtCode").val(),
				"params.name" : $("#txtName").val(),
				"params.phone" : $("#txtPhone").val(),
				"params.typeId" : $("#typeId").val(),
				"params.levelId" : $("#levelId").val(),
				"params.monthlyIncomeId" : $("#incomeId").val(),
				"params.professionId" : $("#professionId").val(),
				"params.hobbiesId" : $("#hobbiesId").val(),
				"params.receiveDoc" : $("#receiveDoc").val()
			});
		}
	</script>
</body>
</html>